﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;
using VIW = CPPEI.ETL.Domain.Views;

namespace CPPEI.ETL.WebApi
{
    /// <summary>
    /// 获取可以使用的数据库的类型列表
    /// </summary>
    [CPPEI.WebApi.AuthGetAction("ETL", "GetDbDataType", "1.0")]
    public class GetDbDataTypeAction : BaseAction<GetDbDataTypeParams, GetDbDataTypeResult>
    {
        protected override ActionResult<GetDbDataTypeResult> OnExecute(ActionContext context,
            SysParameters sysParameters,
            GetDbDataTypeParams opParams)
        {
            string[] types = new string[]{
                "nvarchar",
                "int",
                "bit",
                "uniqueidentifier",
                "datetime",
                "decimal"
            };
            bool[] needLengths = new bool[]{
                true,
                false,
               false,
               false,
               false,
               false
            };

            GetDbDataTypeResult result = new GetDbDataTypeResult();
            for (int index = 0; index < types.Length; index++)
            {
                GetDbDataTypeResult.Item item = new GetDbDataTypeResult.Item();
                item.Name = types[index];
                item.NeedLength = needLengths[index];
                result.Items.Add(item);
            }

            return new ActionResult<GetDbDataTypeResult>(result);
        }
    }

    public class GetDbDataTypeParams
    {
    }

    public class GetDbDataTypeResult
    {
        public List<Item> Items = new List<Item>();

        public class Item
        {
            public string Name { get; set; }
            public bool NeedLength { get; set; }
        }
    }
}
